package com.central.oauth.mobile;

import com.central.oauth.service.IValidateCodeService;
import com.central.oauth.service.MyUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.stereotype.Component;

/**
 * mobile的相关处理配置
 */
@Component
public class MobileCodeAuthenticationSecurityConfig extends
        SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    @Autowired
    private MyUserDetailsService userDetailsService;

    @Autowired
    IValidateCodeService validateCodeService;

    @Override
    public void configure(HttpSecurity http) {
        //mobile code provider
        MobileCodeAuthenticationProvider provider = new MobileCodeAuthenticationProvider();
        provider.setUserDetailsService(userDetailsService);
        // 验证码的模式
        provider.setValidateCodeService(validateCodeService);
        http.authenticationProvider(provider);
    }
}
